import os
import tensorflow as tf
import keras
import numpy as np

def loadImage(path:str) -> np.ndarray:
    max_dim=512
    img=tf.io.read_file(path)
    img=tf.io.decode_image(img,channels=3)
    img = tf.image.convert_image_dtype(img, tf.float32)
    shape = tf.cast(tf.shape(img)[:-1], tf.float32)
    long_dim = max(shape)
    scale = max_dim / long_dim

    new_shape = tf.cast(shape * scale, tf.int32)

    img = tf.image.resize(img, new_shape)
    img = img[tf.newaxis, :]
    return img
def prepareVgg(weightPath) -> keras.Model:
    vgg=keras.applications.VGG19(
        weights=weightPath,
        include_top=False
    )
    for layer in vgg.layers:
        layer.trainable = False
    return keras.Model(inputs=vgg.input, outputs=vgg.output)
if __name__ == '__main__':
    model=prepareVgg()
    img=loadImage('Market-1501/Market-1501-v15.09.15/train/images/0002_c1s1_000451_03.jpg')
    features=model.predict([img])
    print(features)